<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class xcx_model extends model{
	
    //获取微信小程序 TOKEN
    public function getWxxcxToken()
    {
        $config   =   array();
        include(PLUS_PATH.'config.php');
        
        $Token       =  $config['wxxcx_token'];
        $TokenTime   =  $config['wxxcx_token_time'];
        
        $NowTime = time();
        
        if(($NowTime-$TokenTime)>7000 || empty($Token)){
            
            @include(DATA_PATH.'api/wxpay/wxpay_data.php');
            
            $Appid       =  $wxpaydata['sy_xcxappid'];
            $Appsecert   =  $wxpaydata['sy_xcxsecret'];
            $Url         =  'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$Appid.'&secret='.$Appsecert;
            $CurlReturn  =  CurlPost($Url);
            
            $Token  =  json_decode($CurlReturn);
            
            $config['wxxcx_token']       =  $Token->access_token;
            $config['wxxcx_token_time']  =  time();
            
            made_web(PLUS_PATH.'config.php',ArrayToString($config),'config');
            
            return $config['wxxcx_token'];
            
        }else{
            
            return $Token;
        }
    }
    
    public function getQrcode($data = array()){
        
        $token  =  $this->getWxxcxToken();
        
        $post  =  array(
            'scene'  =>  'id='.$data['id'],
            'width'  =>  '280'
        );
        if ($data['type'] == 'job'){
            
            $post['page']  =  'pages/job/show';
            
        }elseif ($data['type'] == 'company'){
            
            $post['page']  =  'pages/company/show';
        }
        
        $Url         =  'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$token;
        $CurlReturn  =  CurlPost($Url, json_encode($post));
        $qrcode      =  json_decode($CurlReturn,true);
        
        header("Content-type: image/png");
        echo $CurlReturn;
    }
}
?>